package com.xiaoshuidi.cloud.module.rooms.controller.admin.reservation;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.reservation.vo.*;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomReservationConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 公寓预定配置
 *
 * @author Feng
 * @since 2023-05-11
 */
@Tag(name = "管理后台 - 公寓预定配置")
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping(ApiConstants.NAME + "/room-reservation-config")
public class RoomReservationConfigController {

    private final IRoomReservationConfigService roomReservationConfigService;


    /**
     * 公寓预定配置编辑
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    @Operation(summary = "公寓预定配置编辑")
    public CommonResult<Boolean> update(@RequestBody @Valid ReservationConfigUpdateReq req) {
        return CommonResult.success(roomReservationConfigService.update(req));
    }


    /**
     * 根据公寓获取预定配置列表
     *
     * @return
     */
    @GetMapping("/page/list")
    @Operation(summary = "根据公寓获取预定配置列表")
    public CommonResult<PageResult<ReservationConfigListResp>> pageList(@Valid ReservationConfigPageReq req) {
        return CommonResult.success(roomReservationConfigService.page(req));
    }

    /**
     * 根据ID获取详情
     *
     * @param id
     * @return
     */
    @GetMapping("/get")
    @Parameter(name = "id", description = "id")
    @Operation(summary = "根据ID获取详情")
    public CommonResult<ReservationConfigResp> get(@NotNull @RequestParam("id") Integer id) {
        return CommonResult.success(roomReservationConfigService.get(id));
    }

    /**
     * 创建预订单配置
     *
     * @param req
     * @return
     */
    @PostMapping("/create")
    @Operation(summary = "创建预定单配置")
    public CommonResult<Long> create(@RequestBody ReservationConfigCreateReq req) {
        return CommonResult.success(roomReservationConfigService.create(req));
    }

    /**
     * 根据公寓id获取预定配置相关信息
     */
    @GetMapping("/get-config")
    @Operation(summary = "根据公寓id获取预定配置")
    public CommonResult<ReservationConfigGetResp> getConfig(@NotNull @RequestParam Long apartmentId) {
        return CommonResult.success(roomReservationConfigService.getConfig(apartmentId));
    }
}
